package com.yix.demo;

import com.yix.util.DBUtil;

import java.sql.Connection;
import java.sql.Statement;

public class SchemaDemo {
    public static void main(String[] args) {
        createSchema();
    }

    private static void createSchema() {
        String databaseName = "my_database"; // 替换为你的数据库名称
        String schemaName = "tp"; // 替换为你的模式名称

        String createSchemaSQL = "CREATE SCHEMA " + schemaName + ";";

        try (Connection conn = DBUtil.getConnection();
             Statement stmt = conn.createStatement()) {
            stmt.execute("SET search_path TO " + schemaName + ";");
            stmt.execute(createSchemaSQL);
            System.out.println("模式 '" + schemaName + "' 创建成功");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private static void deleteSchema() {
        String databaseName = "my_database"; // 替换为你的数据库名称
        String schemaName = "tp"; // 替换为你的模式名称

        String deleteSchemaSQL = "DROP SCHEMA " + schemaName + ";";

        try (Connection conn = DBUtil.getConnection();
             Statement stmt = conn.createStatement()) {
            stmt.execute(deleteSchemaSQL);
            System.out.println("模式 '" + schemaName + "' 删除成功");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
